package es.cea.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class LibroDetail
 */
@WebServlet("/LibroDetail")
public class LibroDetail extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		
	
		PrintWriter writer = response.getWriter();
		try
		{  
			Class.forName("com.mysql.jdbc.Driver");  
			Connection conexion = DriverManager.getConnection ("jdbc:mysql://localhost/libreria","root", "root");  
			Statement s = conexion.createStatement();  
			ResultSet rs = s.executeQuery ("select * from Libros where id_libro = " + request.getParameter("id"));  
			while(rs.next()){
				
			  writer.println("<html><body><table><tr><td><h4> ID Libro " +  rs.getString(1) + "</td></tr><br>");
			  writer.println("<h4><tr><td> Nombre" + rs.getString(2) + "</td></tr><br>" );
			  writer.println("<h4><tr><td> Fecha" + rs.getString(3) + "</td></tr><br>");
			  writer.println("<h4><tr><td> ID Autor" + rs.getString(4) +  "<br><br><a href= ./libros>Volver</a></td></tr><br></table></body></html>");
			  
				
				
			}}
			catch (Exception e)  
			{  
			   e.printStackTrace();  
			}  
		
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	}

}
